package com.budwk.app.sqfwV2.generator.educationalInstitution;


import cn.hutool.core.collection.CollectionUtil;
import cn.hutool.core.date.DateUtil;
import com.budwk.app.sqfwDoc.codeGenerator.pdfGenerate.SqfwPdfCreateCommonBO;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.CompleteFlowBusinessParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.fileParam.PdfGenerateParam;
import com.budwk.app.sqfwDoc.codeGeneratorV2.generate.BasePdfGenerator;
import com.budwk.app.sqfwV2.dto.EducationalInstitutionDTO;
import com.budwk.app.sqfwV2.dto.dulaying.DuLaYingPropagandaOrScreeningPdfDTO;
import com.budwk.app.sys.models.Sys_user;
import com.budwk.app.sys.services.SysUserService;
import com.budwk.app.util.ClassUtil;
import com.budwk.app.util.poiUtils.CommonFormOfficeUtils;
import com.budwk.app.util.poiUtils.nutzBeanUtils.NutzIocUtils;
import com.deepoove.poi.data.PictureRenderData;
import org.nutz.dao.Cnd;

import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class EducationalInstitutionPdfGenerator extends BasePdfGenerator {

    private String templateName;



    public EducationalInstitutionPdfGenerator(){}




    public EducationalInstitutionPdfGenerator(String templateName){
        this.templateName=templateName;
    }



    public String getTemplateName() {
        return this.templateName;
    }


    public boolean pdfCreateConditionCheck(SqfwPdfCreateCommonBO pdfDTO) {
        return false;
    }




    @Override
    protected boolean pdfCreateConditionCheck(PdfGenerateParam pdfGenerateParam) {
        return true;
    }

    @Override
    protected void customerPopularPdfParam(Map<String, Object> paramMap, PdfGenerateParam pdfGenerateParam) {
        EducationalInstitutionDTO landscapePatrolDTO = (EducationalInstitutionDTO) pdfGenerateParam.getAbstractCustomerPdfCreateField();
        paramMap.put("fillDate", DateUtil.format(landscapePatrolDTO.getFillDate(), "yyyy-MM-dd"));
        CompleteFlowBusinessParam businessParam = (CompleteFlowBusinessParam) pdfGenerateParam.getBusinessParam();
        if("直属".equals( businessParam.getFormSummary().getCommunity())){
            paramMap.put("community", "");
        }
        if("直属".equals( businessParam.getFormSummary().getCounty())){
            paramMap.put("county", "");
        }
        // 图片处理
        String images = landscapePatrolDTO.getVisitPictures();
        String fieldName = ClassUtil.getField(DuLaYingPropagandaOrScreeningPdfDTO::getImages);
        List<String> pictureUrlList = images == null ? Arrays.asList("") : Arrays.asList(images.split(","));
        List<Map<String, PictureRenderData>> pictures = CommonFormOfficeUtils.addWordPicture(pictureUrlList, fieldName, 6.0F);
        paramMap.put(fieldName + "s", pictures);

    }


    @Override
    protected String getTemplatePath(PdfGenerateParam pdfGenerateParam) {
        return this.templateName;
    }





}
